/*
 * clcomm.h
 *
 *  Created on: September 10, 2011
 *      Authors: Lane Aasen, Nikholas Gaffney, Michael Rosenberger, Dylan Swiggett
 */

#ifndef CLCOMM_H_
#define CLCOMM_H_

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
#include <ctype.h>

#define INBUFSIZE		2048			/*bytes allocated to the user input buffer*/
#define EBS			256			/*bytes allocated to the regex error buffer*/
#define CMDLEN			64			/*bytes allocated to the command*/
#define MAXFLAG			64			/*maximum number of flags*/
#define FLAGLEN			64			/*bytes allocated to each flag*/
#define MAXARG			512			/*maximum number of arguments*/
#define ARGLEN 			256 			/*bytes allocated to each argument*/
#define USER			"@Aasen: "

/*initializes clcomm with default io*/
/*prepares and compiles regexes*/
/*applies regexes to user input until an exit command is given*/
/*user input is parsed with auxiliary functions (below) and data is sent to the function referened by command*/
int initclcomm();

/*takes in an array of expected flags (expflags) and an array of all flags (allflags)*/
/*then stores the flags that appear in expflags and allflags in a repository of valid flags (valflags)*/
/*the respective lengths of each array are passed in; including valflags (to avoid buffer overflow)*/
/*the number of valid flags is returned*/
int parseflags(char* expflags[], int lenexpflags, char* allflags[], int lenallflags, char* valflags[], int lenvalflags);

/*finds all expressions that match regex in string up to maxmatches (inclusive)*/
/*returns number of matches or -1 for buffer overflow*/
/*only works for regexes with one subexpression*/
int findmatches(char* string, regex_t regex, int numsubexpr, char* matches[], int matchsize, int maxmatches);

/*returns true if stra and strb are equal*/
int strcmpr(char* stra, char* strb);

/*returns true if the array of strings contains the specified string*/
int sarraycont(char* sarray[], int sarraylen, char* string);

#endif /* CLCOMM_H_ */
